/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ee.persistence;

import java.util.HashMap;
import javax.persistence.TypedQuery;
import org.ee.persistence.exception.StoredProcedureException;

/**
 *
 * @author Gabriel Bran <gbran.u@gmail.com>
 */
public abstract class AbstractProcedureModel extends AbstractTemplate {

    public <T> T storeProcedureResult(String procedureName, HashMap<String, Object> parameters, Class<T> resultClass) throws StoredProcedureException {
        try {
            TypedQuery<T> query = getEntityManager().createNamedQuery(procedureName, resultClass);
            return setQueryParameters(query, parameters).getSingleResult();
        } catch (Exception e) {
            throw new StoredProcedureException(e);
        }
    }
}
